export function formatDateWeekday(string) {
    const date = new Date(string);
    const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
    const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];

    const day = date.getDate();
    const month = months[date.getMonth()];
    const weekday = days[date.getDay()];
    const year = date.getFullYear();
    return `${day} ${month}, ${year}, ${weekday}`;
  }

  export function formatDateMonth(string) {
    console.log(string)
    const date = new Date(string);
    const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
    const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];

    const day = date.getDate();
    const month = months[date.getMonth()];
    // const weekday = days[date.getDay()];
    const year = date.getFullYear;
    return `${day} ${month}`;
  }

  export function formatDateYear(string) {
    const date = new Date(string);
    const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
    const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];

    const day = date.getDate();
    const month = months[date.getMonth()];
    // const weekday = days[date.getDay()];
    const year = date.getFullYear();
    return `${day} ${month}, ${year}`;
  }


  export function secondsToHMS(seconds) {
    const hours = Math.floor(seconds / 3600);
    const minutes = Math.floor((seconds % 3600) / 60);
    const secs = seconds % 60;

    let result = '';

    if (hours > 0) {
        result += `${hours} h `;
    }
    if (minutes > 0 || hours > 0) {  // 显示分钟当小时存在或分钟本身大于0
        result += `${minutes} m `;
    }
    result += `${secs} s`;

    return result.trim();
}

export function formatDistance(meters) {
  if (meters < 1000) {
      return `${meters} m`;
  } else {
      const kilometers = meters / 1000;
      return `${kilometers} km`;
  }
}